package com.xbts.web.controller.manager;

import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.core.page.TableDataInfo;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnSolution;
import com.xbts.system.service.ICnSolutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 解决方案Controller
 * @author xbts
 * @date 2023-08-03
 */
@Api("解决方案")
@RestController
@RequestMapping("/system/manager/solution")
public class CnManagerSolutionController extends BaseController {

    @Autowired
    private ICnSolutionService cnSolutionService;

    /**
     * 获取解决方案类型列表
     */
    @ApiOperation("获取解决方案详细信息")
    @ApiImplicitParam(name = "shoppingCarId", value = "解决方案ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @GetMapping(value = "/type/list")
    public AjaxResult getTypeList() {
        return success(cnSolutionService.getTypeList());
    }

    /**
     * 查询解决方案
     */
    @ApiOperation("查询解决方案")
    @PreAuthorize("@ss.hasPermi('system:solution:list')")
    @GetMapping("/list")
    public TableDataInfo getSolutionList(){
        List<CnSolution> cnSolutions = cnSolutionService.selectCnSolution();
        return getDataTable(cnSolutions);
    }

    /**
     * 新增解决方案内容
     */
    @ApiOperation("新增解决方案内容")
    @PreAuthorize("@ss.hasPermi('system:solution:add')")
    @Log(title = "新增解决方案内容", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@Validated @RequestBody CnSolution cnSolution) {
        return toAjax(cnSolutionService.insertCnSolution(cnSolution));
    }


    /**
     * 删除解决方案内容
     */
    @ApiOperation("删除解决方案内容")
    @PreAuthorize("@ss.hasPermi('system:solution:remove')")
    @Log(title = "删除解决方案内容", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "solutionId", value = "解决方案id", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PostMapping("/delete")
    public AjaxResult deleteContent(Long solutionId) {
        return toAjax(cnSolutionService.deleteContentById(solutionId));
    }

    /**
     * 批量删除解决方案内容
     */
    @ApiOperation("批量删除解决方案内容")
    @PreAuthorize("@ss.hasPermi('system:solution:remove')")
    @Log(title = "批量删除解决方案内容", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "ids", value = "解决方案id集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PostMapping("/batchDelete")
    public AjaxResult batchDeleteContent(@RequestBody List<Long> ids) {
        return toAjax(cnSolutionService.batchDeleteContentById(ids));
    }

    /**
     * 更新解决方案内容
     */
    @ApiOperation("更新解决方案内容")
    @PreAuthorize("@ss.hasPermi('system:solution:edit')")
    @Log(title = "更新Solution内容", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult updateContent(@RequestBody CnSolution cnSolution) {
        return toAjax(cnSolutionService.updateSolution(cnSolution));
    }

    /**
     * 获取解决方案详细信息
     */
    @ApiOperation("获取解决方案详细信息")
    @ApiImplicitParam(name = "shoppingCarId", value = "解决方案ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('system:solution:query')")
    @GetMapping(value = "/getInfo")
    public TableDataInfo getInfoByParentId(CnSolution cnSolution) {
        startPage();
        return getDataTable(cnSolutionService.selectCnSolutionByParentId(cnSolution.getParentId()));
    }

    /**
     * 获取解决方案详细信息
     */
    @ApiOperation("获取解决方案详细信息")
    @ApiImplicitParam(name = "shoppingCarId", value = "解决方案ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermi('system:solution:query')")
    @GetMapping(value = "/getById/{solutionId}")
    public AjaxResult getInfo(@PathVariable("solutionId") String solutionId) {
        return success(cnSolutionService.getById(solutionId));
    }
}